package game.players.goalkeeper.mate;

import java.awt.Point;

import game.players.SoccerPlayer;
import game.players.goalkeeper.GoalkeeperState;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.appearances.Animation;
import com.uqbar.vainilla.appearances.Appearance;
import com.uqbar.vainilla.appearances.Sprite;

public class WalkingToTheLeftMate extends GoalkeeperState {
	
	private double i = 0;
	private double j = 0;
	private Point destiny = null;
	private Appearance appearance = new Animation(0.3,
			Sprite.fromImage("/images/arquero_arco.png").crop(21,11,84,77),
			Sprite.fromImage("/images/arquero_arco.png").crop(112,13,84,77),
			Sprite.fromImage("/images/arquero_arco.png").crop(200,13,84,79));

	public WalkingToTheLeftMate(SoccerPlayer player) {
		super(player);
		player.setAppearance(this.appearance);
	}

	public WalkingToTheLeftMate(SoccerPlayer player, int x, int y) {
		super(player);
		player.setAppearance(this.appearance);
		this.setMoveVector(x - this.getPlayer().getX(),y - this.getPlayer().getY());
		this.destiny = new Point(x,y);
	}
	
	public void setMoveVector(double x, double y) {
		while(x>10 || y>10){
			x/=2;
			y/=2;
		}
		this.i = x;
		this.j = y;		
	}

	@Override
	public void update(DeltaState deltaState) {
		if(this.destiny==null){//camina hacia la izquierda hasta pasar la linea de la pelota
			this.getPlayer().move(-10,0);
			if(this.getPlayer().getScene().getSoccerBall().getX() > this.getPlayer().getX())
				this.getPlayer().setState(new GoalkeeperWithoutBallMate(this.getGoalkeeper()));
		}else{//camina hacia la izquierda hacia un punto de destino
			this.getPlayer().move(this.i,this.j);
			if(Point.distance(this.getPlayer().getX(),this.getPlayer().getY(),
					this.destiny.getX(),this.destiny.getY()) < 200)
				this.getPlayer().setState(new GoalkeeperWithoutBallMate(this.getGoalkeeper()));
				
		}

	}

	@Override
	public boolean isWithBall() {
		return false;
	}

	@Override
	public boolean isRight() {
		return false;
	}

}
